package com.ftg.learn.bus.userole_control.controller;

import com.ftg.learn.bus.userole_control.pojo.userole_control;
import com.ftg.learn.bus.userole_control.service.userole_control_service;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@Api(value = "用于角色分配功能",tags = "角色分配")
public class userole_control_controller {
    @Autowired
    userole_control_service ucs;

    @ApiOperation(value = "根据用户名 查询该用户具有的角色信息")
    @PutMapping("/userole/control/queryRoleForUserByUsername/{user_id}")
    public List<Map<String,Object>> queryRoleForUserByUsername(@ApiParam("用户名") @PathVariable String user_id){
        return ucs.queryRoleForUserByUsername(user_id);
    }

    @ApiOperation(value = "为用户分配角色")
    @PostMapping("/userole/control/insert/{userole_control}")
    public int insertOrUpdate(@ApiParam("角色分配信息") @RequestBody userole_control userole_control){
        return ucs.insert(userole_control);
    }

    @DeleteMapping("/userole/control/deletesByUser_id/{user_ids}")
    @ApiOperation("根据用户名 多条删除")
    public int deletesByUser_id(@ApiParam("用户名(多条)") @PathVariable List<String> user_ids){
        return ucs.deletesByUser_id(user_ids);
    }

    @DeleteMapping("/userole/control/deletesByRole_ids/{role_ids}")
    @ApiOperation("根据角色id 多条删除")
    public int deletesByRole_ids(@ApiParam("角色id(多条)") @PathVariable List<String> role_ids){
        return ucs.deletesByRole_ids(role_ids);
    }

}
